extends State

var cooldown: float = 0.0
var time_counter: float = 0.0
var card_added_number: int = 0
var draw_number: int = 0

func enter(params: Array) -> void:
    # get cooldown
    cooldown = params[1]

    # get cards
    _get_deck().connect('card_removed', self, '_on_card_removed_from_deck')
    draw_number = params[0]
    _get_deck().remove_cards_from_top(draw_number, cooldown)
    card_added_number = 0

    # reset time counter
    time_counter = cooldown + 0.001
    pass

func exit() -> void:
    # reset datas
    card_added_number = 0
    cooldown = 0.0
    time_counter = 0.0
    pass

func update(delta: float) -> void:
    if draw_number == card_added_number:
        emit_signal('complete', '', [])
    else:
        time_counter = time_counter + delta
        if time_counter > cooldown:

            time_counter = 0.0
    return

func _on_card_removed_from_deck(c: Card) -> void:
    c.flip()
    _get_hands().add_card(c, -1)
    card_added_number = card_added_number + 1
    pass
